﻿<catel:DataWindow x:Class="LprMiddleWare.Views.SettingsWindow"
                  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:catel="http://catel.codeplex.com"
                  xmlns:ViewModels="clr-namespace:LprMiddleWare.ViewModels"
                  x:TypeArguments="ViewModels:SettingsViewModel"
                  mc:Ignorable="d"
                  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                  >
    
    <!-- Resources -->
    <catel:DataWindow.Resources>

    	<DataTemplate x:Key="DataTemplate1">
            <StackPanel Orientation="Horizontal">
                <TextBox Width="100" Text="{Binding IpAddress}" />
                <Label Content=":" />
                <TextBox Width="50" Text="{Binding Port}" />
                <CheckBox Margin="5,0,0,0" VerticalAlignment="Center" Content="连接" IsChecked="{Binding Enabled}" />
            </StackPanel>
    			
    	</DataTemplate>

    </catel:DataWindow.Resources>

    <!-- Content -->
    <TabControl>
        <TabItem Header="基本">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="300" />
                </Grid.ColumnDefinitions>

                <StackPanel>
                    <Grid >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <GroupBox x:Name="groupBox1" >
                            <GroupBox.Header>
                                <CheckBox Content="车牌保存到数据库" x:Name="saveToDb" IsChecked="{Binding Settings.Save2Db}" />
                            </GroupBox.Header>
                            <StackPanel x:Name="grid1">
                                <Label Content="数据库"
                                       x:Name="label1" />
                                <TextBox 
                        x:Name="textEdit1" 
                        Text="{Binding Settings.DbServer, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
                        IsEnabled="{Binding IsChecked, ElementName=saveToDb}"/>
                                <Label Content="用户名"
                                       x:Name="label2"
                                       Margin="0,5,0,0" />
                                <TextBox 
                        x:Name="textEdit2" 
                        Text="{Binding Settings.DbUserName, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
                        IsEnabled="{Binding IsChecked, ElementName=saveToDb}"/>
                                <Label Content="密码"
                                       VerticalAlignment="Top"
                                       Margin="0,5,0,0" />
                                <TextBox x:Name="textEdit3"
                                 VerticalAlignment="Top" 
                                 Text="{Binding Settings.DbPassWord, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
                                 IsEnabled="{Binding IsChecked, ElementName=saveToDb}"/>
                                <Button Margin="0,10,0,0" Command="{Binding TestDatabaseConnCommand}" IsEnabled="{Binding IsChecked, ElementName=saveToDb}">测试</Button>
                            </StackPanel>
                        </GroupBox>
                    </Grid>

                    <GroupBox Header="图片保存路径" Margin="0,5,0,0">
                        <StackPanel>
                            <Grid Height="22">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="0.8*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <TextBox x:Name="textEdit2_Copy1" Text="{Binding Path=Settings.TargetDirectory, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" />
                                <Button Content="浏览..." 
                                    Visibility="Collapsed"
                                    Command="{Binding BrowseForFolder}"
                                            Grid.Column="1" 
                                            Margin="3,0,0,0" 
                                            Padding="3,0,3,1"/>
                            </Grid>
                        </StackPanel>
                    </GroupBox>

                    <GroupBox Header="前端设备IP" Grid.Column="1" >
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <ListBox x:Name="ipList" 
                         Height="200" 
                         Grid.Row="0" 
                         VerticalAlignment="Stretch" 
                         ScrollViewer.VerticalScrollBarVisibility="Auto"
                         ItemsSource="{Binding Settings.Hosts}" 
                         ItemTemplate="{DynamicResource DataTemplate1}"
                         SelectedItem="{Binding SelectedHost}" SelectionMode="Single" />
                            <UniformGrid VerticalAlignment="Bottom" Grid.Row="1" Rows="1">
                                <Button Content="增加" Command="{Binding AddHostCommand}"/>
                                <Button Content="删除" Command="{Binding RemoveHostCommand}" />
                            </UniformGrid>
                        </Grid>

                    </GroupBox>
                   

                </StackPanel>

            </Grid>
        </TabItem>
        <TabItem Header="数据上传">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="300" />
                </Grid.ColumnDefinitions>

                <StackPanel>
                    <Grid >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <GroupBox x:Name="groupBox2" Grid.Column="1">
                            <GroupBox.Header>
                                <CheckBox Content="同步到远程数据库" x:Name="saveToRemoteDb" IsChecked="{Binding Settings.Save2RemoteDb}" />
                            </GroupBox.Header>
                            <StackPanel x:Name="grid2">
                                <Label Content="数据库"
                                       x:Name="label4" />
                                <TextBox 
                        x:Name="textEdit4" 
                        Text="{Binding Settings.RemoteDbServer, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
                        IsEnabled="{Binding IsChecked, ElementName=saveToRemoteDb}"/>
                                <Label Content="用户名"
                                       x:Name="label5"
                                       Margin="0,5,0,0" />
                                <TextBox 
                        x:Name="textEdit5" 
                        Text="{Binding Settings.RemoteDbUserName, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
                        IsEnabled="{Binding IsChecked, ElementName=saveToRemoteDb}"/>
                                <Label Content="密码"
                                       x:Name="label6"
                                       VerticalAlignment="Top"
                                       Margin="0,5,0,0" />
                                <TextBox x:Name="textEdit6"
                                 VerticalAlignment="Top" 
                                 Text="{Binding Settings.RemoteDbPassWord, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
                                 IsEnabled="{Binding IsChecked, ElementName=saveToRemoteDb}"/>
                                <Button Margin="0,10,0,0" Command="{Binding TestRemoteDatabaseConnCommand}" IsEnabled="{Binding IsChecked, ElementName=saveToRemoteDb}">测试</Button>
                            </StackPanel>
                        </GroupBox>
                    </Grid>

                    <GroupBox  Margin="0,5,0,0">
                        <GroupBox.Header>
                            <CheckBox x:Name="uploadWeiZhangData" IsChecked="{Binding Settings.UploadWeiZhangData}">违章超速数据上传</CheckBox>
                        </GroupBox.Header>
                        <StackPanel>

                            <Label Content="上传接口URL"
                                 VerticalAlignment="Top"
                                 Margin="0,5,0,0" />
                            <TextBox  IsEnabled="{Binding IsChecked, ElementName=uploadWeiZhangData}" Text="{Binding Path=Settings.WeiZhangDataUrl, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Name="uploadUrl" />
                            <Label Content="上传序列号"
                                 VerticalAlignment="Top"
                                 Margin="0,5,0,0" />
                            <TextBox  IsEnabled="{Binding IsChecked, ElementName=uploadWeiZhangData}" Text="{Binding Path=Settings.UploadKey, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Name="uploadSn" />
                            <Label Content="上传单位代码"
                                 VerticalAlignment="Top"
                                 Margin="0,5,0,0" />
                            <TextBox  IsEnabled="{Binding IsChecked, ElementName=uploadWeiZhangData}" Text="{Binding Path=Settings.UploadDwbm, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Name="uploadDwDm" />
                            <Label Content="上传录入账号"
                                 VerticalAlignment="Top"
                                 Margin="0,5,0,0" />
                            <TextBox  IsEnabled="{Binding IsChecked, ElementName=uploadWeiZhangData}" Text="{Binding Path=Settings.UploadLry, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Name="uploadLry" />
                            <Button IsEnabled="{Binding IsChecked, ElementName=uploadWeiZhangData}" Margin="0,5" Content="测试" Command="{Binding TestUploadWebService}" />
                            <Button Content="浏览..." 
                                  Visibility="Collapsed"
                                  Command="{Binding BrowseForFolder}"
                                  Grid.Column="1" 
                                  Margin="3,0,0,0" 
                                  Padding="3,0,3,1"/>

                        </StackPanel>
                    </GroupBox>



                </StackPanel>

            </Grid>
        </TabItem>
        <TabItem Header="过期数据" >
            <GroupBox>
                <GroupBox.Header>
                    <CheckBox x:Name="AutoDelData" Content="自动删除过期数据" IsChecked="{Binding Settings.AutoDelOutdateData}" />
                </GroupBox.Header>
                <StackPanel>
                    <GroupBox Header="视频" Margin="0,5,0,0">
                        <StackPanel>
                            <Label Content="布控报警视频保存天数:" />
                            <TextBox MinWidth="200" 
                             IsEnabled="{Binding IsChecked, ElementName=AutoDelData}"
                             Text="{Binding Path=Settings.BuKongVideoKeepDays, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"/>
                            <Label Content="违法报警视频保存天数:" />
                            <TextBox MinWidth="200" 
                             IsEnabled="{Binding IsChecked, ElementName=AutoDelData}"
                             Text="{Binding Path=Settings.WeiFaVideoKeepDays, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"/>
                            <Label Content="一般视频保存天数:" />
                            <TextBox MinWidth="200" 
                             IsEnabled="{Binding IsChecked, ElementName=AutoDelData}"
                             Text="{Binding Path=Settings.VideoKeepDays, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"/>
                        </StackPanel>
                    </GroupBox>
                    <GroupBox Header="图片" Margin="0,5,0,0">
                        <StackPanel>
                            <Label Content="布控报警图片保存天数:" />
                            <TextBox MinWidth="270" 
                             IsEnabled="{Binding IsChecked, ElementName=AutoDelData}"
                             Text="{Binding Path=Settings.BuKongImageKeepDays, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"/>
                            <Label Content="违法报警图片保存天数:" />
                            <TextBox MinWidth="200" 
                             IsEnabled="{Binding IsChecked, ElementName=AutoDelData}"
                             Text="{Binding Path=Settings.WeiFaImageKeepDays, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"/>
                            <Label Content="一般图片保存天数:" />
                            <TextBox MinWidth="200" 
                             IsEnabled="{Binding IsChecked, ElementName=AutoDelData}"
                             Text="{Binding Path=Settings.ImageKeepDays, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"/>
                        </StackPanel>
                    </GroupBox>
                    <GroupBox Header="一般数据" Margin="0,5,0,0">
                        <StackPanel>
                            <Label Content="布控数据保存天数:" />
                            <TextBox MinWidth="200" 
                             IsEnabled="{Binding IsChecked, ElementName=AutoDelData}"
                             Text="{Binding Path=Settings.BuKongDataKeepDays, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"/>
                            <Label Content="违法数据保存天数:" />
                            <TextBox MinWidth="200" 
                             IsEnabled="{Binding IsChecked, ElementName=AutoDelData}"
                             Text="{Binding Path=Settings.WeiFaDataKeepDays, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"/>
                            <Label Content="一般数据保存天数:" />
                            <TextBox MinWidth="200" 
                             IsEnabled="{Binding IsChecked, ElementName=AutoDelData}"
                             Text="{Binding Path=Settings.DataKeepDays, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"/>
                        </StackPanel>
                    </GroupBox>
                    
                </StackPanel>
            </GroupBox>

        </TabItem>
        
    </TabControl>
    

</catel:DataWindow>
